package com.easy.tool.utils.property;

import com.easy.tool.anno.BeanDes;
import com.easy.tool.anno.MethodDes;
import org.apache.log4j.Logger;

import java.io.InputStream;
import java.util.Properties;

/**
 * @author 高俊
 * @create 2021-09-2021/9/3-9:24
 */
@BeanDes(name = "property工具",des = "操作property文件的工具类")
public class PropertyUtils {

    private static Logger logger = Logger.getLogger(Properties.class);

    /**
     * 获取properties配置文件
     * @param object 当前类
     * @param proName 配置文件名称
     * @return
     */
    @MethodDes(des = "获取properties配置文件",param = {"arg0-> object：当前类","arg1-> proName：配置文件名称"})
    public static Properties getProperties(Object object,String proName){
        // 实例化properties类
        Properties pro = new Properties();

        // 获取类加载器
        ClassLoader classLoader = object.getClass().getClassLoader();
        // 类加载器读取配置文件
        InputStream is = classLoader.getResourceAsStream(proName);
        try {
            // properties类加载文件
            pro.load(is);
        }catch (Exception e){
            logger.error("Properties加载配置文件异常！！！");
        }

        return pro;
    }
}
